var express   = require("express");
var app       =express();

// 解决跨域问题，网上成熟的解决方案，我是直接拷贝的
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});

// index页面的header导航条 
app.get('/index/columnNavJson',function(req,res){
	
    var json={
     "code": "200",
     "message":"一切OK",
     "links": [
        {
            "name": "秒杀",
            "ids": 0,
            "hot":false,    
            "line":1
        },
        {
            "name": "优惠券",
            "ids": 1,
            "hot":false,    
            "line":1
        },
        {
            "name": "闪购",
            "ids": 2,
            "hot":true,    
            "line":0
        },
        {
            "name": "拍卖",
            "ids": 3,
            "hot":false,    
            "line":1
        },
        {
            "name": "服装城",
            "ids": 4,
            "hot":true,    
            "line":0
        },
        {
            "name": "京东超市",
            "ids": 5,
            "hot":true,
            "line":0     
        },
        {
            "name": "生鲜",
            "ids": 6,
            "hot":false,    
            "line":1
        },
        {
            "name": "全球购",
            "ids": 7,
            "hot":false,    
            "line":1
        },
        {
            "name": "京东金融",
            "ids": 8,
            "hot":false,    
             "line":0   
        }
      ]
   	}
	res.send(json);
	res.end();
});
// index页面的左侧产品导航条
app.get('/index/subNavJson',function(req,res){
    
    var json={
     "code": "200",
     "message":"一切OK",
     "subNavData":[
                        {
                            "list":[
                                "冰箱",
                                "彩电",
                                "空调"
                                ],
                                "name":"家用电器"
                         },
                        {
                            "list":[
                                "苹果",
                                "联想",
                                "小米"
                                ],
                                "name":"电脑办公"
                         },
                        {
                            "list":[
                                "宜家",
                                "飞利浦",
                                "小米"
                                ],
                                "name":"家居"
                        }
                    ]
        }
    res.send(json);
    res.end();
});

// index页面的轮播图
app.get('/index/sliderJson',function(req,res){
    
    var json={
    "code": "200",
    "message": "一切ok",
    "imgUrl": [
        "image/temp/1.jpg",
        "image/temp/2.jpg",
        "image/temp/3.jpg",
        "image/temp/4.jpg"
    ]
 }
    res.send(json);
    res.end();
});
// index页面的享生活数据
app.get('/index/goodsListJson',function(req,res){
    
    var json={
        "goods":[
        {
            "title":"京东超市",
            "describe":"天天打折 款款实惠“尽情购”",
            "goodsId":"id_1"
        },
        {
            "title":"智能生活",
            "describe":"引领智能新风尚",
            "goodsId":"id_2"
        },
        {
            "title":"奢侈大牌",
            "describe":"尽享品质生活",
            "goodsId":"id_3"
        }
        ]
 }
    res.send(json);
    res.end();
});
// product页面的左侧大小图
app.get('/product/productImgList',function(req,res){
    var json={
             "bigGoodsImage": {
             "imgurl": "http://img.hb.aicdn.com/c4050a748c5670927b6feca9821f6ba7970565f732dea-ohuMgQ_fw658"
              },
              "smallGoodsList": [
                {
                    "tip": "aaa",
                    "imgurl": "http://img.hb.aicdn.com/c4050a748c5670927b6feca9821f6ba7970565f732dea-ohuMgQ_fw658"
                },
                {
                    "tip": "bbb",
                    "imgurl": "http://img.hb.aicdn.com/4e908c1b5cd6270e92880f786ebbb4354b32fe7e5dd0f-p4bxNO_fw658"
                },
                {
                    "tip": "ccc",
                    "imgurl": "http://img.hb.aicdn.com/ae6acef3a2c2f9193ff0fff25906c94c3ccfce41194c46-P26agk_fw658"
                }
                ]
 }
  
    res.send(json);
    res.end();
});

// 产品详情页，根据id返回对应的产品信息
app.get('/product/goodsIds',function(req,res){
    var _ids = req.query.ids;
    var json='';
    if(_ids=="id_1"){
        json = {
            "title": "联想(Lenovo)拯救者R720 15.6英寸大屏游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑金)",
            "describe": [
                        "【京东电脑节开年大促】3月6号0:00-24:00笔记本超级品类日，仅仅24小时！详情猛戳>>>",
                        "GTX1050 4G独显'吃鸡'利器瞄准游戏本.",
                        "【3.6号疯狂电脑节！限量秒完即止！】1050显卡4G大显存！"
                         ],
            "ids":"id_1"
        }
    } else if(_ids=="id_2"){
        json ={
            "title": "三星（SAMSUNG）C27F390FHC 27英寸 1800R曲率 广视角低蓝光 曲面电脑液晶显示器（HDMI）",
            "describe":[
                        "【6日0点秒杀1299，仅此一天！买曲面选三星！】",
                        "【回馈十万评价，6日0点秒杀829，好价仅此一天】",
                        "【6日0点2399秒杀，京东电脑数码节好价仅此一天，隐线式设计】"
                        ],
            "ids":"id_2"
            }
    } else if(_ids=="id_3"){
        json = { 
            "title": "索尼（SONY） DSC-RX100M5（RX100V）黑卡数码相机 等效24-70mm F1.8-2.8蔡司镜头（WIFI/NFC）",
            "describe": [
                        "【3月6日超秒24小时，快上车】约0.05s超快对焦速度，24张每秒高速连拍，4K视频录制，全新黑卡第五代，口袋里就是世界",
                        "【3.6超级品类日，仅一天，预购从速】",
                        "2029万像素 35倍光学变焦 CMOS传感器 4K高清摄像 wifi无线传输"],
             "ids":"id_3"
            }
    }

    res.send(json);
    res.end();
});
// 省的json
app.get('/product/province',function(req,res){
    var  json = {
        "province":
               [
                    {
                        "name": "北京",
                        "id": 1
                    },
                    {
                        "name": "浙江",
                        "id": 2
                    },
                    {
                        "name": "上海",
                        "id": 3
                    },
                    {
                        "name": "重庆",
                        "id": 4
                    },
                    {
                        "name": "辽宁",
                        "id": 5
                    }
                ]
            }
        
    res.send(json);
    res.end();
});
// 市的json
app.get('/product/city',function(req,res){
    var  json = {
        "city":
               [
                    {
                        "name": "金华",
                        "id": 1
                    },
                    {
                        "name": "义乌",
                        "id": 2
                    },
                    {
                        "name": "永康",
                        "id": 3
                    },
                    {
                        "name": "武义",
                        "id": 4
                    },
                    {
                        "name": "磐安",
                        "id": 5
                    }
                ]
            }
        
    res.send(json);
    res.end();
});
// 区的json
app.get('/product/area',function(req,res){
    var  json = {
        "area":
                [
                    {
                        "name": "婺城区",
                        "id": 1
                    },
                    {
                        "name": "金东区",
                        "id": 2
                    },
                    {
                        "name": "西湖区",
                        "id": 3
                    },
                    {
                        "name": "上城区",
                        "id": 4
                    },
                    {
                        "name": "下城区",
                        "id": 5
                    }
                ]
            }
        
    res.send(json);
    res.end();
});
// 产品详情页商品数量
app.get('/product/goodsCarNum',function(req,res){
    var _n = 1;
    if(req.query.ops =='add'){
        _n++;
    }else if(req.query.ops =='reduce'){
         _n--;
    }
    var  json = { "goodsnum":_n}
    res.send(json);
    res.end();
});
app.listen(1234,function(){
	console.log('1234,首页、产品详情页的中间件')
})